<template>
    <el-dialog
        class="dialog"
        :destroy-on-close="true"
        title="续期"
        :visible.sync="isShow"
        :close-on-click-modal="false"
        @close="onDialogClose"
    >
        <el-form
            ref="form"
            label-width="auto"
            class="form"
            :model="formData"
            :rules="rules"
        >
            <el-form-item label="用户类型" prop="member_type">
                <el-select
                    v-model="formData.member_type"
                    placeholder="请选择用户类型"
                    :disabled="isEdit"
                >
                    <el-option
                        v-for="item in categoriesData"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="持有人" prop="member_xm">
                <el-input
                    v-model="formData.member_xm"
                    maxlength="20"
                    :disabled="isEdit"
                ></el-input>
            </el-form-item>
            <el-form-item label="手机号" prop="phone">
                <el-input
                    v-model="formData.phone"
                    maxlength="20"
                    :disabled="isEdit"
                ></el-input>
            </el-form-item>
            <el-form-item label="有效期" prop="end_time">
                <el-date-picker
                    v-model="formData.end_time"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择有效期"
                    :pickerOptions="pickerOptions"
                ></el-date-picker>
            </el-form-item>
           
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="onDialogClose">取消</el-button>
            <el-button type="primary" @click="onSubmit">确认</el-button>
        </div>
    </el-dialog>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Action, State } from "vuex-class";
import { mixinDialogForm } from "@/mixin/dialog/Form";
import { mixinTime } from "@/mixin/Time";
@Component({
    mixins: [mixinTime, mixinDialogForm]
})
export default class equipmentCardEdit extends Vue {

    // 续期
    @Action("parkTenantCard/renewal") itemEdit: any;
    @State((state) => state.sharing.cardCategories) categoriesData: any;
    // 表单数据
    formData: any = {
        member_xm: "",
        phone: "",
        member_type: "",
        end_time: ""
    };

    editInit(data: any) {
        const me = this as any;
        data.member_type = data.member_type.toString();
        me.formData = Object.assign({}, me.formData, data);
    }
    pickerOptions: any = {
        shortcuts: [
            {
                text: '一个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 1);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '三个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 3);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '六个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 6);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '一年',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 12);
                    picker.$emit('pick', end);
                }
            }
        ]
    };
    /**
     * 校验配置
     *
     * @type {*}
     * @memberof mixinViewRules
     */
    rules: any = {
        member_type: [
            {
                required: true
            }
        ],
        member_xm: [
            {
                required: true
            }
        ],
        end_time: [
            {
                required: true,
                message: "请选择有效期",
                trigger: "blur"
            }
        ]
    };
}
</script>
